namespace IMPlant.Core.Web.Control.GridViewFunction
{
    using IMPlant.Core.Web.Control;
    using IMPlant.Core.Web.Control.Helper;
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class FixRowColumnFunction : ExtendFunction
    {
        public FixRowColumnFunction()
        {
        }

        public FixRowColumnFunction(IMPlant.Core.Web.Control.GridView grid) : base(grid)
        {
        }

        private void _grid_RenderBegin(object sender, HtmlTextWriter writer)
        {
            writer.AddStyleAttribute(HtmlTextWriterStyle.Overflow, "auto");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Position, "relative");
            writer.AddStyleAttribute(HtmlTextWriterStyle.Width, string.IsNullOrEmpty(base._grid.FixRowColumn.TableWidth) ? "100%" : base._grid.FixRowColumn.TableWidth);
            writer.AddStyleAttribute(HtmlTextWriterStyle.Height, string.IsNullOrEmpty(base._grid.FixRowColumn.TableHeight) ? "100%" : base._grid.FixRowColumn.TableHeight);
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
        }

        private void _grid_RenderEnd(object sender, HtmlTextWriter writer)
        {
            writer.RenderEndTag();
        }

        private void _grid_RowDataBoundCell(object sender, GridViewTableCell gvtc)
        {
            TableCell tableCell = gvtc.TableCell;
            GridViewRow gvr = (GridViewRow) tableCell.Parent;
            int num = 0;
            if (((!string.IsNullOrEmpty(base._grid.FixRowColumn.FixRows) && Array.Exists<string>(base._grid.FixRowColumn.FixRows.Split(new char[] { ',' }), delegate (string s) {
                return s == gvr.RowIndex.ToString();
            })) || (!string.IsNullOrEmpty(base._grid.FixRowColumn.FixRowType) && Array.Exists<string>(base._grid.FixRowColumn.FixRowType.Split(new char[] { ',' }), delegate (string s) {
                return s == gvr.RowType.ToString();
            }))) || (!string.IsNullOrEmpty(base._grid.FixRowColumn.FixRowState) && Array.Exists<string>(base._grid.FixRowColumn.FixRowState.Split(new char[] { ',' }), delegate (string s) {
                return s == gvr.RowState.ToString();
            })))
            {
                num++;
                Common.SetAttribute(tableCell, "class", "sw_grid_fixRow", AttributeValuePosition.Last, ' ');
            }
            if (!string.IsNullOrEmpty(base._grid.FixRowColumn.FixColumns) && Array.Exists<string>(base._grid.FixRowColumn.FixColumns.Split(new char[] { ',' }), delegate (string s) {
                return s == gvtc.ColumnIndex.ToString();
            }))
            {
                num++;
                Common.SetAttribute(tableCell, "class", "sw_grid_fixCol", AttributeValuePosition.Last, ' ');
            }
            switch (num)
            {
                case 1:
                    Common.SetAttribute(tableCell, "class", "sw_grid_fixLow", AttributeValuePosition.Last, ' ');
                    return;

                case 2:
                    Common.SetAttribute(tableCell, "class", "sw_grid_fixHigh", AttributeValuePosition.Last, ' ');
                    break;
            }
        }

        protected override void Execute()
        {
            base._grid.RowDataBoundCell += new IMPlant.Core.Web.Control.GridView.RowDataBoundCellHandler(this._grid_RowDataBoundCell);
            base._grid.RenderBegin += new IMPlant.Core.Web.Control.GridView.RenderBeginHandler(this._grid_RenderBegin);
            base._grid.RenderEnd += new IMPlant.Core.Web.Control.GridView.RenderEndHandler(this._grid_RenderEnd);
        }
    }
}

